package com.distortiongames.level27.generation.random
{
	import com.distortiongames.level27.generation.Generator;
	
	/**
	 * ...
	 * @author Jefferson Wagner
	 */
	public class Chance
	{
		protected var currentChance:Number, chanceIncrease:Number, baseChance:Number;
		
		public function Chance(baseChance:Number = 0, chanceIncrease:Number = 0)
		{
			this.baseChance = baseChance;
			this.chanceIncrease = chanceIncrease;
			currentChance = baseChance;
		}
		
		public function copy() : Chance {
			return new Chance(baseChance, chanceIncrease);
		}
		
		public function roll():Boolean
		{
			var success:Boolean = false;
			var chance:Number = Generator.random.nextInt(100);
			if (chance > currentChance)
			{
				currentChance += chanceIncrease;
			}
			else
			{
				currentChance = baseChance;
				success = true;
			}
			return success;
		}
		
		public function getChanceIncrease():Number
		{
			return chanceIncrease;
		}
		
		public function setChanceIncrease(chanceIncrease:Number):void
		{
			this.chanceIncrease = chanceIncrease;
		}
		
		public function getBaseChance():Number
		{
			return baseChance;
		}
		
		public function setBaseChance(baseChance:Number):void
		{
			this.baseChance = baseChance;
			this.currentChance = baseChance;
		}
		
		public function reset():void
		{
			currentChance = baseChance;
		}
	}
}